package com.gogowan.agroenterprise.supply;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;

import com.gogowan.agroenterprise.R;

public class CollectionsActivity extends TabActivity {
	 
    private TabHost tabhost;
    private RadioGroup tabGroup;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.supply_my_collections);
 
        tabhost = getTabHost();
        tabGroup = (RadioGroup) findViewById(R.id.tab_group);
 
        // 这里新建3个的Intent用于Activity的切换
        Intent tab1 = new Intent(this, CollectionSupplyActivity.class);
        Intent tab2 = new Intent(this, CollectionDemandActivity.class);
 
        // 向tabhost里添加tab
        tabhost.addTab(tabhost.newTabSpec("TAB1").setIndicator("TAB1")
                .setContent(tab1));
        tabhost.addTab(tabhost.newTabSpec("TAB2").setIndicator("TAB2")
                .setContent(tab2));
 
        // 给各个按钮设置监听
        tabGroup.setOnCheckedChangeListener(new OnTabChangeListener());
 
    }
 
    private class OnTabChangeListener implements OnCheckedChangeListener {
 
        @Override
        public void onCheckedChanged(RadioGroup group, int id) {
            // TODO Auto-generated method stub
 
            //尤其需要注意这里，setCurrentTabByTag方法是纽带
            switch (id) {
            case R.id.tab1:
                tabhost.setCurrentTabByTag("TAB1");
                break;
            case R.id.tab2:
                tabhost.setCurrentTabByTag("TAB2");
                break;
 
            }
 
        }
    }
 
}
